Skip to main content

Sending Email with Node-RED

This tutorial shows you how to set up automated email notifications from your OV20i camera using Node-RED. You'll learn to configure Gmail integration and create flows that send inspection alerts, system status updates, and failure notifications directly to your email.

What You'll Build: An automated email system that sends OV20i inspection results, alerts, and notifications to specified recipients using Gmail SMTP.

Real-World Application: Get instant email alerts when inspections fail, send daily quality reports to management, or notify maintenance teams of system issues - all automatically from your vision inspection system.

Prerequisites

  • OV20i camera with Node-RED access
  • Gmail account for sending emails
  • Basic understanding of Node-RED flows
  • Access to Google Account security settings

Tutorial Overview

What we'll build: A Node-RED flow that automatically sends email notifications with inspection results and system alerts.

Time required: 20-30 minutes (including Gmail setup)

Skills learned: Gmail app password setup, SMTP configuration, automated email notifications

Step 1: Set Up Gmail App Password

1.1 Enable 2-Step Verification

  1. Sign in to your Google Account at accounts.google.com
  2. Click "Security" in the left navigation menu
  3. Find "Signing in to Google" section
  4. Click "2-Step Verification"
  5. Follow the prompts to enable 2-Step Verification if not already enabled
note

2-Step Verification is required before you can create app passwords.

1.2 Generate App Password

  1. Return to Security page after enabling 2-Step Verification
  2. Click "App passwords" (under "Signing in to Google")
  3. Select "Mail" as the app type
  4. Select "Other" as the device type
  5. Enter a name like "OV20i Node-RED Email"
  6. Click "Generate"

1.3 Save Your App Password

  1. Copy the 16-character password that Google displays
  2. Store it securely - you'll need it for Node-RED configuration
  3. Note: This password is only shown once. If lost, generate a new one

Checkpoint: You should have a 16-character Gmail app password saved for Node-RED use.

Step 2: Install Email Nodes (If Needed)

2.1 Check for Email Nodes

  1. Open Node-RED on your OV20i camera
  2. Look in the left palette for an "email" node in the output section
  3. If missing, you'll need to install the email package

2.2 Install Email Package (If Required)

  1. Click the hamburger menu (≡) in Node-RED
  2. Select "Manage palette"
  3. Click "Install" tab
  4. Search for "node-red-node-email"
  5. Click "Install" next to the package

Step 3: Create Basic Email Flow

3.1 Add Required Nodes

  1. Navigate to IO Block > Configure I/O to access Node-RED
  2. Drag these nodes from the palette to your canvas:
    • Inject node (for testing)
    • Email node (from output section)
  3. Connect inject output to email input

3.2 Basic Flow Structure

Inject → Email

Flow purpose: Simple email sending for testing and basic notifications.

image.png

Step 4: Configure Email Content

4.1 Set Up Inject Node

  1. Double-click the inject node to open properties
  2. Set the payload:
    • Payload type: "string"
    • Payload value: Your email body text (e.g., "Inspection alert from OV20i")
  3. Add email subject:
    • Click "+ add" to add a property

    • Property name: "topic"

    • Property value: Your email subject (e.g., "OV20i Inspection Alert")

      image.png

4.2 Example Basic Configuration

Payload (email body):

Inspection completed at Station 1
Status: Alert triggered
Time: Check timestamp for details

Topic (email subject):

OV20i Inspection Alert - Station 1

4.3 Save Inject Configuration

  1. Give the node a name like "Email Trigger"
  2. Click "Done" to save the configuration

Step 5: Configure Email SMTP Settings

5.1 Set Up Email Node

  1. Double-click the email node to open properties
  2. Configure basic settings:
    • Name: "Send Alert Email" (or descriptive name)
    • To: Recipient email address (e.g., quality@company.com)

5.2 Configure Gmail SMTP

  1. Server: smtp.gmail.com
  2. Port: 465
  3. Check "Use secure connection"
  4. Auth type: Basic
  5. Userid: Your full Gmail address (e.g., alerts@company.com)
  6. Password: The 16-character app password from Step 1

5.3 Security Settings

  1. Check "Check server certificate is valid"
  2. Verify all settings are entered correctly
  3. Click "Done" to save email node configuration

Checkpoint: Your email node should show no error indicators and display the recipient address.

image.png

Step 6: Test Your Email Flow

6.1 Deploy and Test

  1. Click "Deploy" button in the top-right corner
  2. Wait for "Successfully deployed" message
  3. Click the inject node button (gray square on the left side)

6.2 Verify Email Delivery

  1. Check the recipient email for the test message
  2. Check spam folder if email doesn't appear in inbox
  3. Look for any error messages in Node-RED debug panel

6.3 Troubleshoot If Needed

Common issues:

  • Wrong app password: Regenerate Gmail app password
  • SMTP settings: Verify server and port are correct
  • Firewall: Ensure outbound SMTP traffic is allowed

Step 7: Integration with Inspection Results

7.1 Connect to Inspection Flow

To send emails based on inspection results:

  1. Find your main inspection flow (starts with "All Block Outputs")
  2. Add your email flow as a branch from inspection processing
  3. Connect after inspection logic but parallel to final results

7.2 Example Integration Flow

All Block Outputs → [Inspection Logic] → Final Pass/Fail

Format Email → Send Email

image.png

7.3 Dynamic Email Content

Replace the inject node with a function node for dynamic content:

// Dynamic email based on inspection results
const result = msg.payload.result ? "PASSED" : "FAILED";
const timestamp = new Date().toLocaleString();
const station = global.get("station_name") || "Unknown Station";

// Set email subject
msg.topic = `Inspection ${result} - ${station}`;

// Set email body
msg.payload = `Inspection Report:
Status: ${result}
Station: ${station}
Time: ${timestamp}
Image: ${msg.payload.image_url || "No image available"}

Please review and take appropriate action.`;

return msg;

Step 8: Complete Flow Example

8.1 Import Ready-Made Flow

You can import this complete flow JSON:

[
{
"id": "email_node_1",
"type": "e-mail",
"name": "Send Inspection Alert",
"server": "smtp.gmail.com",
"port": "465",
"secure": true,
"authtype": "BASIC",
"to": "quality@company.com"
},
{
"id": "format_email",
"type": "function",
"name": "Format Email Content",
"func": "const result = msg.payload.result ? 'PASSED' : 'FAILED';\nmsg.topic = `Inspection ${result}`;\nmsg.payload = `Status: ${result}\\nTime: ${new Date()}`;\nreturn msg;"
}
]

8.2 Customize for Your Needs

  1. Update email addresses for your organization
  2. Modify email content for your specific requirements
  3. Adjust timing and trigger conditions
  4. Test thoroughly before production deployment

Troubleshooting

Common Issues

ProblemSymptomsSolution
Authentication failed"Login failed" errorsVerify app password is correct and 2-step verification is enabled
Connection timeoutNo email sent, timeout errorsCheck firewall settings, verify SMTP server and port
Emails in spamEmails delivered but in spam folderAdd sender to safe list, improve email content
Flow not triggeringNo debug outputCheck flow connections and trigger conditions

Debug Your Email Flow

  1. Add debug nodes after each step to trace data
  2. Check Node-RED logs for detailed error messages
  3. Test SMTP settings with external email clients if needed
  4. Verify network connectivity from camera to Gmail servers

Success! Your Email Integration is Complete

Your OV20i camera can now:

Send automated email notifications for inspection results

Deliver rich, formatted messages with inspection details

Support multiple recipients and escalation workflows

Provide scheduled reports and summaries

Handle conditional messaging based on inspection outcomes

Best Practices

Email Management

  • Use descriptive subjects with clear status indicators
  • Keep messages concise but informative
  • Include timestamps and station identifiers
  • Provide actionable information in notifications

Security and Reliability

  • Protect app passwords - store securely and rotate regularly
  • Use dedicated email accounts for system notifications
  • Test email delivery regularly to ensure reliability
  • Monitor for delivery failures and have backup notification methods

Performance Considerations

  • Limit email frequency to avoid spam detection
  • Use appropriate recipient lists for different alert types
  • Implement rate limiting for high-volume systems
  • Consider email size when including large attachments

Next Steps

After setting up email notifications:

  1. Create email templates for different types of alerts
  2. Set up distribution lists for various stakeholders
  3. Implement escalation workflows for critical issues
  4. Create scheduled reports for management
  5. Integrate with other notification systems (SMS, Teams, etc.)

🔗 See Also